//
//  main.cpp
//  Amqp_test
//
//  Created by HNXF on 2022/7/26.
//

#include <iostream>
#include "amqpcpp_streamer.h"

int main(int argc, const char * argv[]) {
    // insert code here...
    //http://10.251.100.154:15672       admin   123456     这是rabbitmq 后台管理
    std::cout << "Hello, World!\n";
    
    const std::string topic = "ORS.EX";
    const std::string partition_key = "ORS.ER.MQ.KEY";
    const std::string event_type_name = "ORS.ER.MQ";
    
    std::exception_ptr exception = nullptr;
    auto error_callback = [&exception](std::exception_ptr new_exception)
    {
        exception = new_exception;
    };

    amqpcpp_streamer streamer;
    streamer.set_amqp_param("10.251.100.154", 5672, "/", "admin", "123456", error_callback);
    
    try
    {
        streamer.connect();
        for (int i = 0; i < 5; ++i)
        {
            if (nullptr != exception)
            {
                std::rethrow_exception(exception);
            }

            std::string message(500, 'a'); // 500 bytes message content
            streamer.publish(topic, partition_key, event_type_name, message);
        }
    }
    catch (const std::exception& e)
    {
        std::cout << "Exception in main: " << e.what() << "\n";
    }

    std::cout << std::this_thread::get_id() << ": Done\n";
    getchar();
    return 0;
}
